<template>
  <div>
    <nav-bar title="动火证管理"></nav-bar>
    <div class="maxinBox">
      <div v-if="user && user.userType === '01'" class="backgroundfff hotCardManage">
        <van-tabs type="card" v-model="active" @change="getHotCardDataList">
          <van-tab title="待审批">
            <div v-if="hotCardList.length === 0" class="noData">
              <img src="../../../assets/images/noData.png" alt="">
              <p class="center">暂无数据</p>
            </div>
            <card v-else v-for="(item, index) in hotCardList" :key="index" :itemData="item" @click.native="getDetails(item)"></card>
          </van-tab>
          <van-tab title="已审批">
            <div v-if="hotCardList.length === 0" class="noData">
              <img src="../../../assets/images/noData.png" alt="">
              <p class="center">暂无数据</p>
            </div>
            <card v-else v-for="(item, index) in hotCardList" :key="index" :itemData="item" @click.native="getDetails(item)"></card>
          </van-tab>
        </van-tabs>
      </div>
      <div class="backgroundfff hotCardManage" v-else>
        <div v-if="hotCardList.length === 0" class="noData">
          <img src="../../../assets/images/noData.png" alt="">
          <p class="center">暂无数据</p>
        </div>
        <van-row v-else class="hotCardData" @click="getDetails(item)" v-for="(item,index) in hotCardList" :key="index">
          <van-col :span="24">
            <van-row class="fontSize16" style="color: #333;">
              <van-col :span="7" style="padding: 0 0.3125rem;">
                <img style="width: 100%;" :src="item.licenseUrl" alt="">
              </van-col>
              <van-col :span="12">
                <div style="margin-bottom: 0.3125rem;">{{item.applicant}}</div>
                <div class="fontSize14">监护人：{{item.guardian}}</div>
                <div class="fontSize14">动火级别：
                  <span v-if="item.fireLevel === '1'">I级</span>
                  <span v-else-if="item.fireLevel === '2'">II级</span>
                  <span v-else>III级</span>
                </div>
                <div style="margin-top: 0.3125rem;" class="fontSize14">{{item.effectDate | formatDate('YYYY/MM/DD')}}-{{item.invalidDate | formatDate('YYYY/MM/DD')}}</div>
              </van-col>
              <van-col :span="5" style="text-align: right;">
                <span v-if="item.applyStatus === '1'">待审批</span>
                <span v-else-if="item.applyStatus === '2'">已通过</span>
                <span v-else-if="item.applyStatus === '3'">已驳回</span>
                <span v-else>已过期</span>
              </van-col>
            </van-row>
          </van-col>
        </van-row>
        <div class="marginTop5 backgroundfff">
          <div style="width: 80%;margin: 0 auto;padding: 0.3125rem 0;position: fixed;bottom: 0;left: 10%;">
            <van-button round block type="info" @click="onAddHotCard">
              动火证申请
            </van-button>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  import Card from './components/card.vue'
  import hotCardManageAPI from '../../../api/workAPI/hotCardManageAPI.js'
  export default {
    components: {
      Card
    },
    data() {
      return {
        hotCardList: [],
        active: 0,
        user: {
          userStatus: '',
          userType: '',
        }
      }
    },
    methods: {
      // 动火证列表
      getHotCardList() {
        hotCardManageAPI.getHotCardList().then(res => {
            this.hotCardList = res
        })
      },
      // 动火证审批列表
      getHotCardDataList() {
        hotCardManageAPI.getHotCardDataList(this.active + 1).then(res => {
          this.hotCardList = res
        })
      },
      // 动火证详情
      getDetails(itemData) {
        localStorage.setItem('hotCardDetails', JSON.stringify(itemData))
        this.$router.push({
          name: 'HotCardDetails',
          params: {
            itemData: itemData
          }
        })
      },
      onAddHotCard() {
        this.$router.push({
          name: 'AddHotCard'
        })
      }
    },
    mounted() {
      this.user.userStatus = localStorage.getItem('userStatus')
      this.user.userType = localStorage.getItem('userType')
      if (this.user && this.user.userType === '01') {
        this.getHotCardDataList()
      } else {
        this.getHotCardList()
      }
    }
  }
</script>
<style scoped lang="scss">
  .noData{
    padding: 20% 0;
    width: 100%;
    text-align: center;
    img {
      width: 60%;
    }
  }
  .hotCardManage{
    .hotCardData{
      padding: 0.9375rem;
      font-size: 0.875rem;
      border-bottom: 0.0625rem solid #E5E5E5;
    }
  }
  /deep/ .van-tabs__wrap{
    .van-tabs__nav--card{
      border: inherit;
      margin: inherit;
      .van-tab.van-tab--active{
        background-color: #fff;
        color: #1577FF;
      }
      .van-tab{
        border: inherit;
        color: #999;
        background-color: #EBEBEB;;
      }
    }
  }
</style>
